package com.eagle;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.view.WindowManager;

import com.eagle.support.constants.Constants;
import com.kinstalk.voip.sdk.interfaces.WeaverRequestListener;
import com.kinstalk.voip.sdk.logic.sip.SipLogic;
import com.kinstalk.voip.sdk.model.WeaverRequest;

/**
 * Created by gc on 2016/12/24.
 */
public class EApplication extends Application implements WeaverRequestListener {

    private static EApplication INSTANCE = null;
    /**
     * 屏幕宽度
     */
    private int mScreenWidth = 0;

    /**
     * 屏幕高度
     */
    private int mScreenHeight = 0;

    /**
     * 状态栏高度
     */
    private int mStatusBarHeight = 0;

    /**
     * 导航栏高度
     */
    private int mNavigationBarHeight = 0;

    /**
     * 是否初始化
     */
    public static boolean mInitState;

    public static EApplication getInstance() {
        return INSTANCE;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        INSTANCE = this;
        System.loadLibrary("videorender");
        SipLogic.setLogLevel(1);
        SipLogic.setDefaultVideoSize(320, 240, 640, 480);
        initWindowParams();
    }

    /**
     * 初始化屏幕宽高
     */
    private void initWindowParams() {
        WindowManager wm = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
        mScreenWidth = wm.getDefaultDisplay().getWidth();
        mScreenHeight = wm.getDefaultDisplay().getHeight();

        Resources resourcesStatusBar = getApplicationContext().getResources();
        int resourceStatusBarId = resourcesStatusBar.getIdentifier("status_bar_height", "dimen", "android");
        mStatusBarHeight = resourcesStatusBar.getDimensionPixelSize(resourceStatusBarId);

        Resources resourcesNavigationBar = getApplicationContext().getResources();
        int resourceNavigationBarId = resourcesNavigationBar.getIdentifier("navigation_bar_height", "dimen", "android");
        mNavigationBarHeight = resourcesNavigationBar.getDimensionPixelSize(resourceNavigationBarId);
    }


    /**
     * 获得SharedPreference
     */
    public static SharedPreferences getSharedPreferences() {
        SharedPreferences sharedpreferences = getInstance().getSharedPreferences(Constants.PREFS_FILE_NAME, Context.MODE_PRIVATE);
        return sharedpreferences;
    }

    @Override
    public void onRequestFinshed(WeaverRequest weaverRequest) {

    }

    public int getScreenWidth() {
        return mScreenWidth;
    }

    public int getScreenHeight() {
        return mScreenHeight;
    }

    public int getStatusBarHeight() {
        return mStatusBarHeight;
    }

    public int getNavigationBarHeight() {
        return mNavigationBarHeight;
    }
}
